package com.quarkus.resource;

import com.quarkus.bean.Fruit;
import com.quarkus.service.FruitServiceImpl;

import javax.inject.Inject;
import javax.validation.Valid;
import javax.validation.Validator;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

/**
 * @version v1.0
 * @Description: TODO(一句话描述该类的功能)
 * @Author: TongRui乀
 * @Date: 2021/1/24 6:24 下午
 */
@Path("param")
public class ParamterResource {

    @Inject
    FruitServiceImpl fruitService;


    @GET
    @Path("{name}")
    public String get(@PathParam("name") String name){

        return name;
    }

    @POST
    @Path("fruit")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    public Fruit add(@Valid Fruit fruit){

        return fruit;
    }


    @GET
    @Path("fruit")
    public Fruit addGet(@QueryParam("name") String name, @QueryParam("description") String description){

        var fruit = new Fruit(name, description);

        fruitService.validateV2(fruit);

        return fruit;
    }

}
